package leetcode.editor.day;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

// 1656. 设计有序流
// https://leetcode.cn/problems/design-an-ordered-stream/
class DesignAnOrderedStream {
    public static void main(String[] args) {
        OrderedStream orderedStream = new OrderedStream(5);
        orderedStream.insert(3, "ccccc");
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    static class OrderedStream {

        String[] stream;
        int ptr;
        int n;

        public OrderedStream(int n) {
            stream = new String[n];
            ptr = 0;
            this.n = n;
        }

        public List<String> insert(int idKey, String value) {
            stream[idKey - 1] = value;
            LinkedList<String> res = new LinkedList<>();
            while (ptr < n && stream[ptr] != null) {
                res.add(stream[ptr]);
                ptr++;
            }

            return res;
        }
    }

/**
 * Your OrderedStream object will be instantiated and called as such:
 * OrderedStream obj = new OrderedStream(n);
 * List<String> param_1 = obj.insert(idKey,value);
 */
//leetcode submit region end(Prohibit modification and deletion)

}
